package com.tricode.ile.training.task.sl275.lab11;

import com.tricode.ile.training.task.sl275.lab6.Bank;
import com.tricode.ile.training.task.sl275.lab6.CheckingAccount;
import com.tricode.ile.training.task.sl275.lab6.Customer;
import com.tricode.ile.training.task.sl275.lab6.SavingsAccount;

import java.util.ArrayList;

public class CustomerReport {

    private Bank bank;

    public void setBank(Bank bank) {
        this.bank = bank;
    }

    public void generateReport() {
        System.out.println("Customers Report");
        System.out.println("--------------------------------------------");
        for(Customer customer : bank.getCustomers()){
            printCustomer(customer);
        }
    }

    private void printCustomer(Customer customer) {
        System.out.println("Customer: "+customer.getFirstName()+", "+customer.getLastName());
        ArrayList<SavingsAccount> savingAccounts = customer.getSavingAccounts();
        ArrayList<CheckingAccount> checkingAccounts = customer.getCheckingAccounts();
        printSavingAccounts(savingAccounts);
        printCheckingAccounts(checkingAccounts);
    }

    private void printSavingAccounts(ArrayList<SavingsAccount> savingsAccounts) {
        double sum = 0.0;
        for(SavingsAccount savingAccount : savingsAccounts) {
            sum += savingAccount.getBalance();
        }
        System.out.println("Savings account: current balance is "+sum);
    }

    private void printCheckingAccounts(ArrayList<CheckingAccount> checkingAccounts) {
        double sum = 0.0;
        for(CheckingAccount checkingAccount : checkingAccounts) {
            sum += checkingAccount.getBalance();
        }
        System.out.println("Checking Account: current balance is "+sum);
    }

}
